<template>
    <div>
        <!-- 面包屑导航区 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片区域 -->
        <el-card>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-input placeholder="请输入内容">
                        <el-button slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                </el-col>
            </el-row>

            <el-table :data="orderlist" border stripe>
                <el-table-column type="index"></el-table-column>
                <el-table-column label="订单编号" prop="order_number"></el-table-column>
                <el-table-column label="订单价格" prop="order_price"></el-table-column>
                <el-table-column label="是否付款" prop="pay_status">
                    <template v-slot="scope">
                        <el-tag type="danger" v-if="scope.row.pay_status === '0'">未付款</el-tag>
                        <el-tag type="success" v-else>已付款</el-tag>

                    </template>
                </el-table-column>
                <el-table-column label="是否发货" prop="is_send"></el-table-column>
                <el-table-column label="下单时间" prop="create_time">
                    <template v-slot="scope">
                        {{ scope.row.create_time | dateFromat }}
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <!--  v-slot="scope" -->
                    <template>
                        <el-button sizi="mini" type="primary" icon="el-icon-edit" @click="showBox"></el-button>
                        <el-button sizi="mini" type="success" icon="el-icon-location" disabled
                            @click="showProgress"></el-button>
                    </template>
                </el-table-column>

            </el-table>

            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="queryInfo.pagenum" :page-sizes="[5, 10, 15, 20]" :page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </el-card>


        <!-- 修改地址对话框 -->
        <el-dialog title="修改地址" :visible.sync="orderDialogVisible" width="50%" @close="addressDialogColsed">
            <el-form :model="orderForm" :rules="orderFormRules" ref="orderFormRef" label-width="100px">
                <el-form-item label="省市区/县" prop="address1">
                    <el-cascader :options="cityData" v-model="orderForm.address1"></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="orderForm.address2"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="orderDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="orderDialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>


        <!-- 修改物流进度的对话框 -->
        <el-dialog title="物流进度" :visible.sync="progressDialogVisible" width="50%">
            <!-- <el-form :model="progressForm" :rules="progressFormRules" ref="progressFormRef" label-width="100px"> -->
            <el-timeline>
                <el-timeline-item v-for="(activity, index) in progressInfo" :key="index" :timestamp="activity.time">
                    {{ activity.context }}
                </el-timeline-item>
            </el-timeline>
            <!-- </el-form> -->

        </el-dialog>
    </div>
</template>
<script>
import cityData from './citydata';
export default {
    data() {
        return {
            queryInfo: {
                query: '',
                pagenum: 1,
                pagesize: 10
            },
            total: 0,
            //列表数据绑定对象的数组
            orderlist: [],
            //控制 修改地址对话框的显示和隐藏
            orderDialogVisible: false,
            orderForm: {
                address1: [],
                address2: ''
            },
            orderFormRules: {
                address1: [
                    { required: true, message: '请输入省市区县', trigger: 'blur' },
                ],
                address2: [
                    { required: true, message: '请输入详细地址', trigger: 'blur' },
                ]
            },
            cityData,
            progressDialogVisible: false,
            progressInfo: []
        }
    },
    created() {
        this.getOrderlist()
    },
    methods: {
        async getOrderlist() {
            const res = await this.$gethp('get', 'orders', { params: this.queryInfo })
            this.total = res.total
            this.orderlist = res.goods
        },
        handleSizeChange(newSize) {
            this.queryInfo.pagesize = newSize
            this.getOrderlist()
        },

        handleCurrentChange(newPage) {
            this.queryInfo.pagenum = newPage
            this.getOrderlist()
        },
        //显示修改地址对话框
        showBox() {
            this.orderDialogVisible = true
        },
        //关闭时清空 输入栏
        addressDialogColsed() {
            this.$refs.orderFormRef.resetFields()
        },
        //获取查看物流信息列表
        async showProgress() {

            this.progressInfo = await this.$gethp('get', `/kuaidi/1106975712662`)
            this.progressDialogVisible = true
        }
    }

}
</script>
<style lang="less" scoped>
.el-cascader {
    width: 100%;
}
</style>